package com.ablog.controller;

import com.ablog.model.Admin;
import com.ablog.service.AdminService;
import com.ablog.util.ResultUtil;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Admin)表控制层
 *
 * @author mopeiwen
 * @since 2020-07-22 13:17:37
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
	/**
	 * 服务对象
	 */
	@Resource
	private AdminService adminService;

	/**
	 * 管理员登录
	 * 
	 * @param username 账号
	 * @param password 密码
	 * @return 返回管理员信息
	 */
	@PostMapping(value = "/login")
	public ResultUtil login(String username, String password) {
		return ResultUtil.ok("登录成功", adminService.login(username, password));
	}

	/**
	 * Select list ResultUtil.
	 *
	 * @param admin
	 * @return the ResultUtil
	 */
	@GetMapping(value = "/query-all")
	public ResultUtil queryAll(Admin admin) {
		return ResultUtil.ok("查询列表", adminService.queryAll(admin));
	}

	/**
	 * Select obj ResultUtil.
	 *
	 * @param id
	 * @return the ResultUtil
	 */
	@GetMapping(value = "/query")
	public ResultUtil queryById(@RequestParam("id") String id) {
		return ResultUtil.ok("查询详情", adminService.queryById(id));
	}

	/**
	 * Insert obj ResultUtil.
	 *
	 * @param admin
	 * @return the ResultUtil
	 */
	@PostMapping(value = "/add")
	public ResultUtil add(@RequestBody Admin admin) {
		return ResultUtil.ok("添加成功", adminService.add(admin));
	}

	/**
	 * update obj ResultUtil.
	 *
	 * @param admin
	 * @return the ResultUtil
	 */
	@PutMapping(value = "/update")
	public ResultUtil update(@RequestBody Admin admin) {
		return ResultUtil.ok("更新成功", adminService.update(admin));
	}

	/**
	 * delete obj ResultUtil.
	 *
	 * @param id
	 * @return the ResultUtil
	 */
	@DeleteMapping(value = "/del")
	public ResultUtil delById(@RequestParam("id") String id) {
		return ResultUtil.ok("删除成功", adminService.delById(id));
	}
}